﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;

namespace ConfigEditor
{
    
    public partial class MainWindow
    {


        public void InitializeCommand()
        {

            CommandBindings.Add(new CommandBinding(Commands.Check, OnCheckCommand, CommandCheck_CanExecute));
            CommandBindings.Add(new CommandBinding(Commands.ClearOutput, OnClearOutputCommand, CommandClearOutput_CanExecute));

            CommandBindings.Add(new CommandBinding(ApplicationCommands.Save, OnSaveCommand, CommandSave_CanExecute));
            CommandBindings.Add(new CommandBinding(ApplicationCommands.Open, OnOpenCommand, CommandOpen_CanExecute));

        }


        private void CommandSave_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = Uc.IsModified;
            //if (e.CanExecute == false)
            //    e.ContinueRouting = false;
        }
        private void OnSaveCommand(object sender, ExecutedRoutedEventArgs e)
        {
            Uc.Save();
        }

        private void CommandOpen_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }
        private void OnOpenCommand(object sender, ExecutedRoutedEventArgs e)
        {
            Uc.Open();
        }



        private void CommandCheck_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {

            e.CanExecute = Uc.ItemCanCheck;

            if (e.CanExecute == false)
                e.ContinueRouting = false;

        }
        private void OnCheckCommand(object sender, ExecutedRoutedEventArgs e)
        {
            Uc.CheckCurrentSection();
        }


        private void CommandClearOutput_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {

            e.CanExecute = Uc.CanClearOutput;

            if (e.CanExecute == false)
                e.ContinueRouting = false;

        }

        private void OnClearOutputCommand(object sender, ExecutedRoutedEventArgs e)
        {
            StatutList.Items.Clear();
        }


    }







    public static class Commands
    {

        #region Fields
        private static readonly Type ThisType = typeof(MainWindow);
        #endregion

        #region Commands

        private static readonly RoutedUICommand _check = new RoutedUICommand("Check", "check", ThisType);
        private static readonly RoutedUICommand _clearOutput = new RoutedUICommand("Clear", "clearOutput", ThisType);


        public static RoutedUICommand Check { get { return _check; } }
        public static RoutedUICommand ClearOutput { get { return _clearOutput; } }


        #endregion

    }
   
}
